// 引包
const Mock = require('mockjs');
const mongoose = require("mongoose");
// 构建数据结构
const schema = new mongoose.Schema({
    name: String,
    age:String ,
    sex:String,
    tel: String,
    email: String,
    city: String,
    class:{
        type:mongoose.Schema.Types.ObjectId,
        ref:"class"
    },
    imgs:[String],
});
// 构建数据模型
const studentsModel=mongoose.model("students",schema,"students");
// 生成数据
const data = Mock.mock({
    "students|30": [{
        "name": "@cname",
        "age": "@integer(16,26)",
        "sex": "@string('男女',1)",
        "tel": /^[1][3-9][\d]{9}$/,
        "email": "@email",
        "city": "@county(true)",
        // 随机一个班级的_id
        "class|1":["605163e43429a55909366f76","605163ec3429a55909366f77","605163c33429a55909366f75"]
    }]
});


console.log(`111111111111`);


// 连接数据库
mongoose.connect('mongodb://localhost:27017/F72', {
    useNewUrlParser: true,
    useUnifiedTopology: true,
}, async ()=>{
//   数据已生成
//    let data1= await studentsModel.create(data.students);

 
});